package com.ten.course.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ten.common.core.entity.TbPlayHistory;
import com.ten.common.core.vo.Result;
import com.ten.course.service.PlayHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：张成（3092211427@qq.com）
 * @date ：Created in 2022/12/28 13:48
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/core/play-history")
@Api(tags = "用户观看课程历史的接口类")
public class PlayHistoryController {
    @Autowired
    private PlayHistoryService playHistoryService;

    /**
     * 根据会员id分页查询会员观看课程的历史记录
     * @param currentPage 当前页码
     * @param pageSize 当前页面显示条数
     * @param memberId 会员id
     * @return
     */
    @ApiOperation(value = "根据会员id分页查询会员观看课程的历史记录")
    @PostMapping("queryPlayHistoryBy/{currentPage}/{pageSize}/{memberId}")
    public Result<Page<TbPlayHistory>> queryPlayHistoryBy(@PathVariable Integer currentPage,
                                                          @PathVariable Integer pageSize,
                                                          @PathVariable String memberId){
        return playHistoryService.queryPlayHistoryBy(currentPage,pageSize,memberId);
    }

    /**当用户访问课程时，对于观看课程的历史记录进行添加
     * @param courseId  课程id
     * @param huiYuanId 会员id
     * @param videoId   视频id
     *       在初次观看的时候，进行添加，后来观看更新记录
     * @return
     */
    @ApiOperation(value = "当用户访问课程时，对于观看课程的历史记录进行添加")
    @PostMapping("insertPlayHistoryByCourseId/{courseId}/{huiYuanId}/{videoId}")
    public Result insertPlayHistoryByCourseId(@PathVariable String courseId,
                                              @PathVariable String huiYuanId,
                                              @PathVariable String videoId){
        return playHistoryService.insertPlayHistoryByCourseId(courseId,huiYuanId,videoId);
    }
}